use driver::APP_INFO;
use proto_bytes::frame::ToEc;
use utils::{log, ufmt::{self, derive::uDebug}};

use crate::error::AppErr;


pub mod service;
pub mod driver;
pub mod status;
pub mod handler;
mod draw_water_task;
mod water_heat_task;
mod steam_heat_task;
pub mod request_task;

#[derive(Clone, Copy, uDebug)]
pub enum HeatErr {
    Temp = 0x11,
    MoveMotorAlm = 0x12,
    MoveMotorTimeout = 0x13,
    StirCapAlm = 0x14,
    StirCapTimeout = 0x15,
    IceConn = 0x16,
    Store = 0x17,
    FlowArgInvalid = 0x18,
    DrawFail = 0x19,
    ClampOpenTimeout = 0x1A,
    ClampCloseTimeout = 0x1B,
    TrunMoveTimeout = 0x1C,
    TrunResetTimeout = 0x1D,
    StirCapNotClose = 0x1E,
}

impl ToEc for HeatErr {
    fn to_ec(self) -> u8 {
        self as u8
    }
}

impl From<HeatErr> for AppErr {
    fn from(value: HeatErr) -> Self {
        AppErr::Heat(value)
    }
}

pub unsafe fn init() {
    driver::init();

    let ret =  APP_INFO.lock().load();
    log!("appinfo load: {:?}", ret);

    service::init();
    status::init();

    draw_water_task::start();
    water_heat_task::start();
    steam_heat_task::start();
    request_task::start();
}
